package com.sky.mapper;

import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {

    /**
     * 根据菜品id查询套餐id
     *
     * @param dishIds
     * @return
     */

    List<Long> getSetmealIdsByDishIds(List<Long> dishIds);

    /**
     * 批量插入与套餐相关联的菜品
     *
     * @param setmealDishes
     */

    void insertBatch(List<SetmealDish> setmealDishes);

    /**
     * 批量删除与套餐相关联的菜品
     *
     * @param ids
     */
    void deleteBySetmealId(List<Long> ids);

    /**
     * 根据套餐id查询套餐相关联的菜品相关信息
     *
     * @param setmealId
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id=#{setmealId}")
    List<SetmealDish> getBySetmealId(Long setmealId);

    /**
     * 删除相关的菜品
     *
     * @param setmealId
     */
    @Delete("delete from setmeal_dish where setmeal_id=#{setmealId}")
    void delete(Long setmealId);

    /**
     * 根据套餐id查询包含的菜品
     * @param setmealId
     * @return
     */
    @Select("SELECT sd.name,sd.copies,d.image,d.description\n" +
            "FROM setmeal_dish sd \n" +
            "JOIN dish d \n" +
            "ON d.id=sd.dish_id\n" +
            "WHERE setmeal_id=36")
//    @Select("select sd.name, sd.copies, d.image, d.description " +
//            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
//            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemByid(Long setmealId);
}
